package integrated

import (
	"talent.com/agency_im/common/interceptors"
	"talent.com/agency_im/common/pay"
	"talent.com/agency_im/modules/core"
)

func init() {
	interceptors.RegisterMessageInterceptor(&AgencyPayInterceptor{})
	interceptors.RegisterTopicLifeCycleListener(&AgencyTopicListener{})
}

func ProcessSelectPayTypeByAgency(agencyID uint64, playerID uint64, payType pay.PayType) error {
	var (
		err     error
		receipt *pay.ReceiptAddress
	)

	if receipt, err = pay.GetAgencyReceiptAddress(playerID, agencyID, payType, true); err != nil {
		errorInfo := "当前系统繁忙，请稍候重试"
		switch err.Error() {
		case "3302":
			errorInfo = "该支付方式当前不可用，请选择其他支付方式"
		case "3303":
			errorInfo = "您已被禁用，若有疑问请联系在线客服"
		case "3304":
			errorInfo = "该玩家已被您拉黑"
		default:
			return err
		}
		core.SendErrorMsg(agencyID, errorInfo)
		return nil
	}

	return handleReceiptAddress(receipt, agencyID, playerID)
}
